package com.finance.cooperate.dao.support.jpa;

import com.finance.cooperate.common.utils.DateUtils;
import com.finance.cooperate.dao.support.constant.DeleteStatus;
import com.finance.cooperate.dao.support.pojo.BaseAutomaticVO;

import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;

/**
 * @ClassName EntityListener
 * @Description 创建日期、修改日期处理
 * @Author shen
 * @Date 2022/5/25 16:20
 * @Modify ...
 */
public class EntityListener {


    /***
     * @Author shen
     * @Description 保存前处理
     * @Date 7:10 下午 2020/10/23
     * @Param [entity]
     * @return void
     **/
    @PrePersist
    public void prePersist(BaseAutomaticVO entity) {

        entity.setCreated(DateUtils.getMillis());
        entity.setUpdated(DateUtils.getMillis());
        entity.setIsDeleted(DeleteStatus.NO);

    }

    /***
     * @Author shen
     * @Description 更新前处理
     * @Date 7:12 下午 2020/10/23
     * @Param [entity]
     * @return void
     **/
    @PreUpdate
    public void preUpdate(BaseAutomaticVO entity) {
        entity.setUpdated(DateUtils.getMillis());
    }

}
